
#include <cstdio>
#include <algorithm>

using namespace std; 

#define N 101

int score[5][5] = {
	{5, -1, -2, -1, -3}, 
	{-1, 5, -3, -2, -4}, 
	{-2, -3, 5, -2, -2}, 
	{-1, -2, -2, 5, -1}, 
	{-3, -4, -2, -1, -1000}
}; 

char sa[N], sb[N]; 
int ia[N], ib[N]; 
int na, nb;
int f[N][N]; 

//"ACGT"; 

inline int c2i(char c)
{
	switch(c) {
	case 'A': return 0; 
	case 'C': return 1; 
	case 'G': return 2; 
	case 'T': return 3; 
	default: return 4; 
	}
	return 4; 
}; 

int main()
{
	int i, j; 
	
	//freopen("p1140_2.in", "r", stdin); 
	scanf("%d %s", &na, sa+1); 
	scanf("%d %s", &nb, sb+1); 
	
	//printf("%d %s, %d %s\n", na, sa+1, nb, sb+1); 
	
	for (i=1; i<=na; i++) {
		ia[i] = c2i(sa[i]); 
		f[i][0] = f[i-1][0] + score[ia[i]][4]; 
        //printf("%d ", ia[i]); 
	}
	//printf("\n"); 
	
	for (i=1; i<=nb; i++) {
		ib[i] = c2i(sb[i]); 
		f[0][i] = f[0][i-1] + score[4][ib[i]]; 
        //printf("%d ", ib[i]); 
	}
	//printf("\n"); 
	
	for (i=1; i<=na; i++) {
		for (j=1; j<=nb; j++) {
			f[i][j] = -20000000; 
			f[i][j] = max(f[i][j], f[i][j-1]+score[4][ib[j]]);
            //printf("(%d, %d) 1--> %d, %d, %d\n", i, j, f[i][j], f[i][j-1], score[4][ib[j]]); 
			f[i][j] = max(f[i][j], f[i-1][j]+score[ia[i]][4]);
            //printf("(%d, %d) 2--> %d, %d, %d\n", i, j, f[i][j], f[i-1][j], score[ia[i]][4]); 
			f[i][j] = max(f[i][j], f[i-1][j-1]+score[ia[i]][ib[j]]);
            //printf("(%d, %d) 3--> %d, %d, %d\n", i, j, f[i][j], f[i-1][j-1], score[ia[i]][ib[j]]); 
		}
	}
/*
    for(int i=0;i<=na;i++) {
        for(int j=0;j<=nb;j++)
        {
			printf("%3d ", f[i][j]); 
        }
        printf("\n"); 
    }
*/
	printf("%d\n", f[na][nb]); 

	return 0; 
}


